import { allGet } from '@/services/pc';
import { useEffect } from 'react';
import { useHistory } from 'umi';

const useKf = () => {
  const { location } = useHistory();
  const getJs = async () => {
    if (document.getElementById('cgjoy-kefu')) {
      return;
    }
    const response = await allGet({ params: { mod: 'setting', do: 'kefu', version: 'pc1.0' } });
    const script = document.createElement('script');
    script.id = 'cgjoy-kefu';
    if (response.success) {
      script.src = response.data;
      document.body.appendChild(script);
    }
  };
  useEffect(() => {
    if (location.pathname.includes('/center/video/player')) return;
    console.log('加在客服js');
    getJs();
  }, []);

  return null;
};

export default useKf;
